package com.boot.webflux.routes;

import com.boot.webflux.service.UserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;

/**
 * Created by Wuxiang on 2017/12/13.
 *
 * 路由类
 *
 * RouterFunction 类似于 @RequestMapping
 */
@Configuration
public class Routes {
    private UserService userService;

    public Routes(UserService userService) {
        this.userService = userService;
    }

    @Bean
    public RouterFunction<?> routerFunction() {
        return
                route(GET("/api/user").and(accept(MediaType.APPLICATION_JSON)), userService::handleGetUsers)
                        .and(route(GET("/api/user/{id}").and(accept(MediaType.APPLICATION_JSON)), userService::handleGetUserById));
//				.and(route(POST("/users"), userHandler::handleGetUsers));

    }
}
